/*
 * @Date: 2022-02-14 11:24:10
 * @LastEditors: 春贰
 * @gitee: https://gitee.com/chun22222222
 * @github: https://github.com/chun222
 * @Desc:
 * @LastEditTime: 2022-09-02 15:14:02
 * @FilePath: \server\system\controller\sys\sysfile\sysfile.go
 */
package sysfile

import (
	"go2admin_pure/system/core/db"
	"go2admin_pure/system/core/request"
	"go2admin_pure/system/core/response"
	"go2admin_pure/system/model/RequestModel"
	"go2admin_pure/system/service/FileService"
	"github.com/gin-gonic/gin"
)

var this FileService.FileService

/**
*
* @api {post} /user/list 用户列表
* @apiName 用户列表
* @apiGroup 用户
* @apiVersion  1.0.0
*
* @apiBody  {String}  page
* @apiBody  {String}  pageSize
* @apiSampleRequest /user/list
* @apiHeader {String} Authorization 唯一token
*
* @apiParamExample  {json} Request-Example:
* {
*    key : "value",
* }
*
*
* @apiSuccessExample {json} Success-Response:
*
{
 "code": 0,
	"data": {
	},
	"msg": "sucess"
}
*
*
*/
func List(c *gin.Context) {
	response.OkWithData(
		this.List(), c)
}

func Tables(c *gin.Context) {
	tables, _ := db.Instance().Migrator().GetTables()
	response.OkWithData(
		tables, c)
}

func Upload(c *gin.Context) {
	var r RequestModel.FileUpload

	if err := c.ShouldBind(&r); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	if err := this.Upload(r, c); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	} else {
		response.Ok(c)
	}
}

func CreateDir(c *gin.Context) {
	var r RequestModel.FileUpload
	if err := c.ShouldBind(&r); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	this.CreateDir(r)
	response.Ok(c)
}

func Remove(c *gin.Context) {
	var r RequestModel.FileUpload
	err, msg := request.Binding(&r, c)
	if err != nil {
		response.FailWithMessage(msg, c)
		return
	}

	if err = this.Remove(r); err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	} else {
		response.Ok(c)
	}
}
